package cn.tedu.submarine;

import javax.swing.*;

/**
 * 战舰类
 */
public class Battleship extends SeaObject {

    private int life;

    public Battleship() {
        super(66, 26, 270, 124, 25);
        life = 5;
    }

    @Override
    public void move() {
        System.out.println("战舰移动...");
    }

    /**
     * 获得对象图片
     *
     * @return 返回对象的图片
     */
    @Override
    public ImageIcon getImage() {
        return Images.battleship;
    }

    /**
     * 发射炸弹-------生成炸弹对象
     *
     * @return 炸弹类对象
     */
    public Bomb shootBomb() {
        return new Bomb(this.x, this.y);
    }

    /**
     * 左移
     */
    public void moveLeft() {
        if (x >= 0)
            x -= speed;
    }

    /**
     * 右移
     */
    public void moveRight() {
        if (x <= World.WIDTH - this.width)
            x += speed;
    }

    /**
     * 战舰得命
     */
    public void addLife(int num) {
        life += num;
    }

    public int getLife() {
        return life;
    }

    /**
     * 战舰命数减1
     * @return
     */
    public void subtractLife(){
        life--;
    }
}
